import { createRouter, createWebHistory } from 'vue-router'

// 思考：为什么要使用路由懒加载？当路径匹配时才去加载对应的组件
import Layout from '@/layout/index.vue'
import Login from '@/views/login/index.vue'

const routes = [
  {
    path: '/',
    component: Layout,
    children: [
      {
        path: 'user',
        component: () => import('@/views/user/index.vue'),
      },
      {
        path: 'user/create',
        component: () => import('@/views/user/create.vue'),
      },
    ],
  },
  {
    path: '/login',
    component: Login,
  },
]

const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes,
})

export default router
